package com.atguigu.ssyx.activity.service.impl;

import com.atguigu.ssyx.client.product.ProductFeignClient;
import com.atguigu.ssyx.enums.SkuType;
import com.atguigu.ssyx.model.activity.SeckillSku;
import com.atguigu.ssyx.vo.activity.SeckillSkuQueryVo;
import com.atguigu.ssyx.vo.activity.SeckillSkuVo;
import com.atguigu.ssyx.vo.product.SkuStockLockVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.ssyx.activity.service.SeckillSkuService;
import com.atguigu.ssyx.activity.mapper.SeckillSkuMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
* @author LiJun
* @description 针对表【seckill_sku(秒杀活动商品关联)】的数据库操作Service实现
* @createDate 2025-05-11 20:52:31
*/
@Service
public class SeckillSkuServiceImpl extends ServiceImpl<SeckillSkuMapper, SeckillSku>
    implements SeckillSkuService{
    @Autowired
    private ProductFeignClient productFeignClient;

    @Override
    public IPage<SeckillSku> selectPage(Page<SeckillSku> pageParam, SeckillSkuQueryVo seckillSkuQueryVo) {
        Long seckillId = seckillSkuQueryVo.getSeckillId();
        Long seckillTimeId = seckillSkuQueryVo.getSeckillTimeId();
        LambdaQueryWrapper<SeckillSku> queryWrapper = new LambdaQueryWrapper<>();
        if (seckillId != null) {
            queryWrapper.eq(SeckillSku::getSeckillId, seckillId);
        }
        if (seckillTimeId != null) {
            queryWrapper.eq(SeckillSku::getSeckillTimeId, seckillTimeId);
        }
        return this.page(pageParam, queryWrapper);
    }

    @Override
    public void save(List<SeckillSku> seckillSkuList) {
        this.saveBatch(seckillSkuList);

        //更新sku为秒杀商品
        List<Long> skuIdList = seckillSkuList.stream().map(SeckillSku::getSkuId).collect(Collectors.toList());
        //productFeignClient.updateSkuType(skuIdList, SkuType.SECKILL);
    }

    @Override
    public void saveSeckillSkuListToCache(String date) {

    }

    @Override
    public List<SeckillSkuVo> findSeckillSkuListFromCache(String timeName) {
        return null;
    }

    @Override
    public SeckillSkuVo getSeckillSkuVo(Long skuId) {
        return null;
    }

    @Override
    public Boolean checkAndMinusStock(List<SkuStockLockVo> skuStockLockVoList, String orderToken) {
        return null;
    }

    @Override
    public void rollBackStock(String orderNo) {

    }
}




